<template>
  <view class="normal-login-container">
    <view class="item-wrap">
      <view class="lineBottom10">
        <uni-section title="修改残值" type="line"/>
      </view>

      <view style="margin: 8rpx 20rpx 8rpx 20rpx">
        <uni-forms ref="ruleForm" :model="ruleForm" labelWidth="auto" :label-position="boole ? 'top' : 'left'">


          <uni-forms-item label="初期残值(元):">
            <uni-easyinput v-model="ruleForm.initialResidualValue" v-if="boole" disabled placeholder="初期残值(元):"/>
            <text v-else>{{ ruleForm.initialResidualValue || '-' }}</text>
          </uni-forms-item>

          <uni-forms-item label="最新残值(元):">
            <uni-easyinput v-model="ruleForm.latestResidualValue" v-if="boole" disabled placeholder="最新残值(元):"/>
            <text v-else>{{ ruleForm.latestResidualValue || '-' }}</text>
          </uni-forms-item>

          <uni-forms-item label="申请修改残值(元):" name="commitResidualValue" :required="boole"
                          :rules="[{required:true, errorMessage: '申请修改残值(元)',validateTrigger:'bind'}]">
            <text class="commitResidualValue"/>
            <uni-easyinput v-model="ruleForm.commitResidualValue" v-if="boole"
                           @change="handleChange"
                           placeholder="申请修改残值(元):"/>
            <text v-else>{{ ruleForm.commitResidualValue || '-' }}</text>
          </uni-forms-item>

          <uni-forms-item label="说明:">
            <text class="specification"/>
            <uni-easyinput type="textarea" v-if="boole" v-model="ruleForm.specification" :maxlength="500" placeholder="说明"/>
            <text v-else>{{ ruleForm.specification || '-' }}</text>
          </uni-forms-item>


          <uni-forms-item label="附件:">
            <image-common :disabled="!boole" :up-type="2" v-model="ruleForm.attachmentOss"/>
          </uni-forms-item>
        </uni-forms>
      </view>
    </view>

  </view>
</template>

<script>

export default {
  name: 'residual',
  props: {
    value: {
      type: Object,
      default: {},
    },
    boole: {
      type: Boolean,
      default: true,
    }
  },
  computed: {
    ruleForm: {
      get() {
        let that = this
        const proxy = new Proxy(that.value, {
          get(target, key) {
            return Reflect.get(target, key)
          },
          set(target, key, value) {
            that.$emit('input', {...target, [key]: value})
            return true
          },
        })
        return proxy
      },
    },
    handleLabel() {
      return function (arr, type) {
        let name = ''
        arr.map((v) => {
          if (type == v.value) {
            name = v.label
          }
        })
        return name
      }
    },
  },
  watch: {},
  data() {
    return {}
  },
  created() {
  },
  mounted() {
  },
  methods: {
    handleChange(val) {
      let msg = /^(?:[1-9]\d*|0)(?:\.\d+)?$/;
      if (!msg.test(val)) {
        this.ruleForm.commitResidualValue = this.value.commitResidualValue = "";
      } else {
        this.ruleForm.commitResidualValue = this.value.commitResidualValue = val
            .toString()
            .match(/^\d+(?:\.\d{0,2})?/)[0];
      }
    },

    handleEffect() {
      return new Promise((resolve, reject) => {
        this.$refs.ruleForm
            .validate()
            .then((res) => {
              resolve()
            })
            .catch((err) => {
              let key = '.flex-col' + '>>>' + '.' + err[0].key
              reject(key)
            })
      })
    },
  },
}
</script>

<style scoped lang="scss">
</style>


